//package com.pipi.config;
//
//import java.util.LinkedHashMap;
//import java.util.Map;
//import org.apache.shiro.mgt.SecurityManager;
//import org.apache.shiro.session.mgt.SessionManager;
//import org.apache.shiro.spring.LifecycleBeanPostProcessor;
//import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
//import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
//import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
//import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
//import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import com.pipi.shiro.UserRealm;
//
///**
// * Shiro配置
// *
// * @author chenshun
// * @email sunlightcs@gmail.com
// * @date 2017-04-20 18:33
// */
//@Configuration
//public class ShiroConfig {
//
//	@Bean(name = "sessionManager")
//	public SessionManager sessionManager() {
//		DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
//		// 设置session过期时间为1小时(单位：毫秒)，默认为30分钟
//		sessionManager.setGlobalSessionTimeout(60 * 60 * 1000);
//		sessionManager.setSessionValidationSchedulerEnabled(true);
//		sessionManager.setSessionIdUrlRewritingEnabled(false);
//		return sessionManager;
//	}
//
//	@Bean(name = "securityManager")
//	public SecurityManager securityManager(UserRealm userRealm, SessionManager sessionManager) {
//		DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
//		securityManager.setRealm(userRealm);
//		securityManager.setSessionManager(sessionManager);
//
//		return securityManager;
//	}
//
//	@Bean("shiroFilter")
//	public ShiroFilterFactoryBean shirFilter(org.apache.shiro.mgt.SecurityManager securityManager) {
//		ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
//		shiroFilter.setSecurityManager(securityManager);
//		shiroFilter.setLoginUrl("/login.html");
//		// shiroFilter.setSuccessUrl("/index.html");
//		shiroFilter.setUnauthorizedUrl("/");
//
//		Map<String, String> filterMap = new LinkedHashMap<>();
//		filterMap.put("/public/**", "anon");
//		filterMap.put("/iot/img/**", "anon");
//		filterMap.put("/iot/app/**", "anon");
//		filterMap.put("/iot/mqtt/**", "anon");
//		filterMap.put("/webjars/**", "anon");
//		filterMap.put("/api/**", "anon");
//
//		// swagger配置
//		filterMap.put("/swagger**", "anon");
//		filterMap.put("/v2/api-docs", "anon");
//		filterMap.put("/swagger-resources/configuration/ui", "anon");
//
//		filterMap.put("/login.html", "anon");
//		filterMap.put("/sys/login", "anon");
//		filterMap.put("/captcha.jpg", "anon");
//		filterMap.put("/**", "authc");
//		shiroFilter.setFilterChainDefinitionMap(filterMap);
//
//		return shiroFilter;
//	}
//
//	@Bean(name = "lifecycleBeanPostProcessor")
//	public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
//		return new LifecycleBeanPostProcessor();
//	}
//
//	@Bean
//	public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
//		DefaultAdvisorAutoProxyCreator proxyCreator = new DefaultAdvisorAutoProxyCreator();
//		proxyCreator.setProxyTargetClass(true);
//		return proxyCreator;
//	}
//
//	@Bean
//	public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
//		AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
//		advisor.setSecurityManager(securityManager);
//		return advisor;
//	}
//
//}
